package com.kimehwa.studyboot.mainTestThread;

import java.util.concurrent.*;

public class ExecutorTest {
    public static final int MAX_TURN =5;
    public static final int COMPUTE_TIMES = 100000000;


    private static ExecutorService pool = Executors.newFixedThreadPool(3);

    static class DemoThread implements Runnable{

        @Override
        public void run() {
            for (int i = 1; i < MAX_TURN ; i++) {
                System.out.println(Thread.currentThread().getName()+"轮次"+i);
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    static class ReturnableTask implements Callable<Long>{

        @Override
        public Long call() throws Exception {
            long startTime = System.currentTimeMillis();
            for(int j = 1;j<MAX_TURN;j++){
                System.out.println(Thread.currentThread().getName()+"轮次"+j);
                Thread.sleep(10000);
            }
            long used = 1000;
            return used;
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        pool.execute(new DemoThread());
        pool.execute(()->{
            for(int j = 1;j<MAX_TURN;j++){
                System.out.println(Thread.currentThread().getName()+"轮次"+j);
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Future<Long> future = pool.submit(new ReturnableTask());
        Long aLong = future.get();
        System.out.println(aLong+"异步执行的结果为");

    }




}
